package middeware

import (
	"github.com/gorilla/mux"
	"log"
	"net/http"
	"time"
)

func Logging() mux.MiddlewareFunc {
	//创建中间件
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			//中间件处理逻辑
			start := time.Now()
			defer func() {
				log.Println(r.Method, r.URL.Path, time.Since(start))
			}()
			h.ServeHTTP(w, r)
		})
	}
}
